//
//  YBSelectShareSingalData.m
//  GongXinDangJian
//
//  Created by apple on 17/12/4.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "YBSelectShareSingalData.h"


static YBSelectShareSingalData * _instance = nil;

static dispatch_once_t onceToken;

@implementation YBSelectShareSingalData


+(instancetype)getYBSelectShareSingalData{
    dispatch_once(&onceToken, ^{
        if (_instance == nil) {
            _instance = [[super alloc]init];
            _instance.selectArray = [NSMutableArray array];
        }
    });
    return _instance;
}



-(void)ybAddObjectToArrayWithModel:(YBPeopleInfoModel *)model{
    NSArray * tempArray = [self.selectArray copy];
    BOOL isExist = NO;
    for (YBPeopleInfoModel * tempModel in tempArray) {
        if ([tempModel.ID isEqualToString:model.ID]) {
            isExist = YES;
            break;
        }
    }
    if (!isExist) {
        [self.selectArray addObject:model];
    }
}


-(void)ybRemoveObjectFromArrayWithModel:(YBPeopleInfoModel *)model{
    NSArray * tempArray = [self.selectArray copy];
    for (YBPeopleInfoModel * tempModel in tempArray) {
        if ([tempModel.ID isEqualToString:model.ID]) {
            [self.selectArray removeObject:tempModel];
            break;
        }
    }
}


-(NSArray *)getCurrentSelectIdArray{
    NSMutableArray * tempArray = [NSMutableArray array];
    for (YBPeopleInfoModel * model in self.selectArray) {
        [tempArray addObject:model.ID];
    }
    return [tempArray copy];
}

+(void)attempDealloc{
    onceToken = 0; // 只有置成0,GCD才会认为它从未执行过.它默认为0.这样才能保证下次再次调用shareInstance的时候,再次创建对象.
    _instance = nil;
}


@end
